package cate.game.activity.diamondbowl.paycallback;

import cate.common.table.d.GDFunc;
import cate.common.table.pay.PayItemRow;
import cate.common.util.GameResult;
import cate.game.GameBody;
import cate.game.activity.diamondbowl.DiamondBowlActivity;
import cate.game.pay.PayCallback;
import cate.game.pay.PayHandler;
import cate.game.role.Role;
import cp.solution.business.pay.PayRecordEntity;
import cp.solution.business.pay.dto.PayDeliverResult;
import easy.java.dev.note.NoteClass;

@NoteClass("聚宝盆支付回调")
@PayHandler(funcIds = {GDFunc.ACT_DIAMOND_BOWL})
public class DiamondBowlPayCallback extends PayCallback {
    @Override
    public void onSuccess(GameBody game, Role role, PayRecordEntity record, PayDeliverResult result) {
        PayItemRow pir = game.table.pay.item.get(record.itemTid);
        if (pir == null) {
            return;
        }
        DiamondBowlActivity single = role.getActivity().getEnableActivitySingle(pir.funcId);
        if (single != null) {
            single.onPaySuccess(pir);
        }
    }

    @Override
    public void onFail(GameBody game, Role role, PayRecordEntity record, PayDeliverResult result) {

    }

    @Override
    public GameResult<Void> allowPay(Role role, PayItemRow pir) {
        DiamondBowlActivity single = role.getActivity().getEnableActivitySingle(pir.funcId);
        if (single == null) {
            return new GameResult<Void>().fail("活动未开启");
        }
        return single.allowPay(pir);
    }
}
